/**
 * @author: dn-jinmin/dn-jinmin
 * @doc:
 */

package toolx

import (
	"aiworkc/internal/domain"
	"aiworkc/pkg/httpx"
	"encoding/json"
	"errors"
)

var (
	Success = `executes successfully. `

	SuccessWithData = `
executes successfully.
After you have determined the final answer, you should not make changes to the content, do not summarize the content, do not output your thoughts, and only keep the output of the original results.
Keep the output in json format as follows.\n
`
)

func ResParser(v []byte, chatType domain.AiChatType, err error) (string, error) {
	if err != nil {
		return "", err
	}

	var res httpx.Response
	if err := json.Unmarshal(v, &res); err != nil {
		return "", err
	}

	if res.Code != 200 {
		return "", errors.New(res.Msg)
	}

	switch chatType {
	case domain.TodoAdd:
		return Success, err
	}

	data := domain.ChatResp{
		ChatType: int(chatType),
		Data:     res.Data,
	}

	d, err := json.Marshal(data)
	if err != nil {
		return "", err
	}

	return SuccessWithData + string(d) + "\n\n\n", nil

}
